<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/js/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/admin/css/common.css" media="all">
    <script src="/js/layui/layui.all.js"></script>

</head>
<body>
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-form layui-card-header layuiadmin-card-header-auto">
            <div class="layui-form-item">

                <div class="layui-inline">
                    <label class="layui-form-label">电影名称</label>
                    <div class="layui-input-block">
                        <input type="text" class="layui-input" id="name" placeholder="请输入电影名称">
                    </div>
                </div>





            </div>

            <div class="layui-inline">
                <button style="margin-left: 50px" id="btnSearch" class="layui-btn layuiadmin-btn-admin" type="button"
                        lay-filter="LAY-user-back-search">
                    <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>搜索
                </button>
            </div>
        </div>


    </div>
</div>

<script type="text/html" id="caozuo">
    <input type="button" value="播放" class="layui-btn layui-btn-sm" lay-event="play"/>
    <input type="button" value="下载" class="layui-btn layui-btn-sm" lay-event="down"/>
</script>

<table id="t" lay-filter="t">
</table>
</body>
</html>

<script>
    var table = layui.table;
    table.render({
        elem: "#t",
        url: "/dy/search",
        id: 'tt',
        limit:50,
        cols: [[
            {title: "序号", width: "80", align: "center", fixed: "left",templet:function(d){
                        return '<div>' + (d.LAY_TABLE_INDEX+1) + '</div>';
                }},
            {field: 'program_name', title: "名称", width: "200", align: "center"},
            {field: 'program_type', title: "类别", width: "160", align: "center",templet:function(d){
                  if (d.program_type_name) {
                      return d.program_type_name;
                  }else {
                      return d.program_type;
                  }
                }},
            {title: "图片", width: "100", align: "center",templet:function(d){
                    return '<img src="/images/'+d.local_img+'"></img>';
                }},
            {field: 'copyright_expiration_time', title: "下架时间", width: "180", align: "center"},
            ,
            {title: "操作", width: "100", align: "center", toolbar: '#caozuo'}
        ]],
        page: true
    });

    var form = layui.form;
    form.render('select');

    var $ = layui.$;
    $("#btnSearch").click(function () {
        //layer.msg("测试工",{icon:1,time:1000})
        table.reload('tt', {
            where: {
                name: $("#name").val(),
            },
            page: {curr: 1}
        });

    });


    //    右侧按钮的的监听事件
    table.on('tool(t)', function (obj) {
        var getdata = obj.data //获得当前行数据
        var layEvent = obj.event //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
        var tr = obj.tr //获得当前行 tr 的 DOM 对象（如果有的话）
        switch (layEvent) {
            case 'down':
                layer.confirm("只有确定不能播放的情况，一般才下载!确定要下载吗?",["确定","取消"],function(){



                    $.ajax({
                        url:'/dy/down',
                        data:{id:getdata.id},
                        success:function(data){
                            if (data.code==200)
                            {
                                layer.msg("已加入下载计划",{icon:1,time:1000},function(){
                                    location.reload();
                                });
                            }else{
                                layer.msg(data.msg,{icon:1,time:1000});
                            }
                        }
                    })
                });
                break;

            case "play":


                var url  = getdata.play_url;
                layer.open({
                    title:getdata.program_name+"-"+url,
                    type: 2,
                    area:['800px','500px'],
                    content: 'play.html?url='+url//这里content是一个URL，如果你不想让iframe出现滚动条，你还可以content: ['http://sentsin.com', 'no']
                });
                break;
        }
    });



</script>